-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logstash controller unit and integration tests #6575
Logstash controller unit and integration tests #6575
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for adding the tests. Mostly looks good to me. I left three comments for you to consider.
wantErr: false, | ||
}, | ||
{ | ||
name: "configRef takes precedence", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "config takes precedence"
pkg/controller/logstash/pod.go
Outdated
|
||
// GetLogstashContainer returns the Logstash container from the given podSpec. | ||
func GetLogstashContainer(podSpec corev1.PodSpec) *corev1.Container { | ||
return pod.ContainerByName(podSpec, "logstash") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a constant for the container name https://github.com/elastic/cloud-on-k8s/blob/feature/logstash/pkg/apis/logstash/v1alpha1/logstash_types.go#L17
}, | ||
}, | ||
} | ||
for _, tt := range tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add test coverage for custom ports, annotation and readinessProbe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (I think...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Added tests for readiness probes and annotations. Updated readiness probe to pick up port from API service
bfda607
to
c8523ce
Compare
Also updated to take account of pipelines
55a0b93
to
d2dd060
Compare
cd90d6a
to
873bb47
Compare
@barkbay Ready for another round |
@elasticmachine run elasticsearch-ci/docs |
var port = network.HTTPPort | ||
for _, service := range logstash.Spec.Services { | ||
if service.Name == LogstashAPIServiceName { | ||
port = int(service.Service.Spec.Ports[0].Port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed it during the first review but .Service.Spec.Ports
can be empty. It is possible for a user to crash the operator by creating a Service
with an empty slice, for example:
apiVersion: logstash.k8s.elastic.co/v1alpha1
kind: Logstash
metadata:
name: logstash-sample
spec:
count: 2
version: 8.6.1
config:
log.level: info
api.http.host: "0.0.0.0"
api.http.port: 9601
queue.type: memory
services:
- name: api
service:
spec:
type: ExternalName
externalName: foo
ports: []
The slice length must be checked before accessing the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed
var port = network.HTTPPort | ||
for _, service := range logstash.Spec.Services { | ||
if service.Name == ls.LogstashAPIServiceName { | ||
port = int(service.Service.Spec.Ports[0].Port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we should check the length of the slice before accessing the index 0
@barkbay Nice find! I've pushed a fix and added a test to verify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This commit adds extra unit tests for the Logstash Controller, including tests for config, controller, pods and services